using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
namespace MicroMsg.Scene
{
	public class NetSceneUploadMContact : NetSceneBaseEx<UploadMContactRequest, UploadMContactResponse, UploadMContactRequest.Builder>
	{
		private const string TAG = "NetSceneUploadMContact";
		private List<MobileContact> mContactList;
		public bool doScene(List<MobileContact> listContact)
		{
			if (listContact == null)
			{
				Log.smethod_1("NetSceneUploadMContact", "listContact == null");
				EventCenter.postEvent(EventConst.ON_NETSCENE_UPLOADCONTACT_FAIL, null, null);
				return false;
			}
			this.mContactList = listContact;
			Account curAccount = AccountMgr.getCurAccount();
			if (curAccount.strUsrName.Equals(""))
			{
				Log.smethod_1("NetSceneUploadMContact", "Have not band a PhoneNumber");
				EventCenter.postEvent(EventConst.ON_NETSCENE_UPLOADCONTACT_FAIL, null, null);
				return false;
			}
			Log.smethod_5("NetSceneUploadMContact", "currentAcc.strMobile = " + curAccount.strBindMobile);
			Log.smethod_5("NetSceneUploadMContact", "currentAcc.strUsrName = " + curAccount.strUsrName);
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			using (List<MobileContact>.Enumerator enumerator = this.mContactList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					MobileContact current = enumerator.get_Current();
					if (current.strMD5 != null && !current.strMD5.Equals(""))
					{
						if (current.nType == 0)
						{
							Mobile mobile = new Mobile.Builder
							{
								V = current.strMobile
							}.Build();
							this.mBuilder.MobileListList.Add(mobile);
							Log.smethod_5("NetSceneUploadMContact", "Mobile.v = " + mobile.V);
						}
						else
						{
							if (current.nType == 1)
							{
								this.mBuilder.EmailListList.Add(MEmail.CreateBuilder().SetV(current.strMD5).Build());
							}
						}
					}
				}
			}
			this.mBuilder.MobileListSize = this.mBuilder.MobileListList.get_Count();
			this.mBuilder.EmailListSize = this.mBuilder.EmailListList.get_Count();
			this.mBuilder.Mobile = curAccount.strBindMobile;
			this.mBuilder.UserName = curAccount.strUsrName;
			this.mBuilder.Opcode = 1;
			this.mSessionPack.mCmdUri = "/cgi-bin/micromsg-bin/uploadmcontact";
			this.mSessionPack.mConnectMode = 2;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(UploadMContactRequest request, UploadMContactResponse response)
		{
			Log.smethod_1("NetSceneUploadMContact", "Upload my contact failed system error!");
			EventCenter.postEvent(EventConst.ON_NETSCENE_UPLOADCONTACT_FAIL, null, null);
		}
		protected override void onSuccess(UploadMContactRequest request, UploadMContactResponse response)
		{
			if (response != null && response.BaseResponse.Ret == 0)
			{
				Log.smethod_4("NetSceneUploadMContact", "Upload my contact success");
				long nUploadTime = (long)Util.getNowMilliseconds() / 1000L;
				using (List<MobileContact>.Enumerator enumerator = this.mContactList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						MobileContact current = enumerator.get_Current();
						current.nUploadTime = nUploadTime;
					}
				}
				StorageMgr.mobileContact.updateList(this.mContactList);
				EventCenter.postEvent(EventConst.ON_NETSCENE_UPLOADCONTACT_SUCCESS, null, null);
				NetSceneGetMFriend netSceneGetMFriend = new NetSceneGetMFriend();
				netSceneGetMFriend.doScene(0);
				return;
			}
			Log.smethod_1("NetSceneUploadMContact", "Upload my contact response not invalidate");
			EventCenter.postEvent(EventConst.ON_NETSCENE_UPLOADCONTACT_FAIL, null, null);
		}
	}
}
